
#include <hal_types.h>
#include <hal_defs.h>
#include <hal_cc8051.h>
#include <ioCCxx10_bitdef.h>
#include "epd_ses_266.h"
#include "stdio.h"
#include "lunar.h"
// #include "lunar.h"
#if (chip == 2510)
#include <ioCC2510.h>
#endif
#if (chip == 1110)
#include <ioCC1110.h>
#endif
#if (chip == 2511)
#include <ioCC2511.h>
#endif
#if (chip == 1111)
#include <ioCC1111.h>
#endif

void gpio_init(void)
{
    P0SEL = 0;
    P1SEL = 0;
    P2SEL = 0;
    P0DIR = 0xff;
    P1DIR = 0xff;
    P2DIR = 0xff;
    P0 |= BIT0;
    P0DIR &= ~(BIT7);
    P1DIR &= ~(BIT3);
    P1 &= ~(BIT0 | BIT6 | BIT5 | BIT4 | BIT7);
    EPD_PWR = 0;
    DelayMS(80);
}

char buf[100];
char buf2[50];
int main(void)
{
    gpio_init();
    EPD_2IN66_Init();
    EPD_2IN66_Clear();
    EPD_2IN66_Init_Partial();
    EPD_DrawFonts(116 + 5, 1, 10, ":", (const epdFONT_ascii *)&Ascii_DigitalDismay_47X80, NULL, NEW_RAM | OLD_RAM);
    sprintf(buf, "%02d", 20);
    EPD_DrawFonts(20 + 5, 1, 10, buf, (const epdFONT_ascii *)&Ascii_DigitalDismay_47X80, NULL, NEW_RAM | OLD_RAM);
    sprintf(buf, "%02d", 47);
    EPD_DrawFonts(155 + 5, 1, 10, buf, (const epdFONT_ascii *)&Ascii_DigitalDismay_47X80, NULL, NEW_RAM | OLD_RAM);
    static struct Lunar_Date Lunar;
    LUNAR_SolarToLunar(&Lunar, (uint16_t)(23 + 2000), 2, 27);
    sprintf(buf, "20%02d年%02d月%02d日 星期%s", 23, 2, 27, Lunar_DayString[1]);

    EPD_DrawFonts(64, 12, 1, buf, (const epdFONT_ascii *)&Ascii_YouYuan_8x16, (const epdFONT_utf8 *)&utf8_CN_16x16, NEW_RAM | OLD_RAM);
    uint8_t day = 0;
    uint8_t JQday = GetJieQiStr((uint16_t)(23 + 2000), 2, 27,
                                &day);
    if (day == 0)
    {
        sprintf(buf2, "今天是%s", JieQiStr[JQday % 24]);
    }
    else
    {
        sprintf(buf2, "离%s还有【%02d】天", JieQiStr[JQday % 24], day);
    }

    sprintf(buf, "农历:%s%s %s%s【%s】年", Lunar_MonthString[Lunar.Month],
            Lunar_DateString[Lunar.Date], Lunar_StemStrig[LUNAR_GetStem(&Lunar)],
            Lunar_BranchStrig[LUNAR_GetBranch(&Lunar)], Lunar_ZodiacString[LUNAR_GetZodiac(&Lunar)]);
    EPD_DrawFonts(25, 14, 1, buf, (const epdFONT_ascii *)&Ascii_YouYuan_8x16, (const epdFONT_utf8 *)&utf8_CN_16x16, NEW_RAM | OLD_RAM);
    EPD_DrawFonts(25, 16, 1, buf2, (const epdFONT_ascii *)&Ascii_YouYuan_8x16, (const epdFONT_utf8 *)&utf8_CN_16x16, NEW_RAM | OLD_RAM);
    Draw_Battery(264, 16, 310, 220, 300);

    EPD_2IN66_TurnOnDisplay();
    EPD_2IN66_Sleep();

    // EPD_PWR =1;
    while (1)
    {
    }
}
